package com.zlop.dao;

import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.google.common.collect.Maps;
import com.nyvi.support.base.dao.BaseDAO;
import com.zlop.common.utils.CollectionUtils;
import com.zlop.model.SysAccountDO;

/**
 * 系统账户表DAO实现
 * 
 * @author	曾令鹏
 * @since	1.0
 * @version 2018年5月8日 曾令鹏
 */
@Repository
public class SysAccountDAO extends BaseDAO<SysAccountDO> {
	
	/**
	 * 通过账户获取记录
	 * 
	 * @param account 账号
	 * @return 查询成功返回对应记录。反之，返回null
	 */
	public SysAccountDO getEntity(String account) {
		Map<String, Object> paramMap = Maps.newHashMap();
		paramMap.put("account", account);

		StringBuilder sql = new StringBuilder(128);
		sql.append("select id, account, amounts from sys_account where account=:account for update");

		RowMapper<SysAccountDO> rowMapper = BeanPropertyRowMapper.newInstance(SysAccountDO.class);
		List<SysAccountDO> list = getNamedParameterJdbcTemplate().query(sql.toString(), paramMap, rowMapper);
		return CollectionUtils.isEmpty(list) ? null : list.get(0);
	}
	

}
